<?php
/**
 * 定义对于用户信息更改请求的操作
 *
 * @todo
 * @author Judas <judasnow@gmail.com>
 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
 */
class update_user_info_process{

	private $db ;
	private $db_obj_user;
	private $db_obj_user_profile;

	function __construct( $db , $username ){
		
		$this->db = $db ;
		$this->db_obj_user = new db_obj_user( $this->db );

		if ( !$this->db_obj_user->username_exists( $username )){
			throw new Exception( '此用户名不存在' );
		}

		$this->db_obj_user->load( 'username' , $username );

		$this->db_obj_user_profile = new db_obj_user_profile( $this->db );
		$this->db_obj_user_profile->load( 'username' , $username );
	}
	
	function update_password( $new_password ){
		
		$this->db_obj_user->set( 'passwd' , md5($new_password) );
		$this->db_obj_user->save();

		return true ;
	}

	function update_email( $new_email ){

		$this->db_obj_user->set( 'email' , $new_email );
		$this->db_obj_user->save();

		return true ;
	}

	function update_nick( $new_nick ){
		
		$this->db_obj_user_profile->set( 'nick' , $new_nick );
		$this->db_obj_user_profile->save();

		return true ;
	}

	function update_motto( $new_motto ){
	
		$this->db_obj_user_profile->set( 'motto' , $new_motto );
		$this->db_obj_user_profile->save();

		return true ;
	}

	function update_location( $new_location ){
	
		$this->db_obj_user_profile->set( 'location' , $new_location );
		$this->db_obj_user_profile->save();

		return true ;
	}

	function update_sex( $new_sex ){
	
		$this->db_obj_user_profile->set( 'sex' , $new_sex );
		$this->db_obj_user_profile->save();

		return true ;
	}
}

